<template>
    <van-tabs v-model="tabs.index" color="#00CC00" class="order-list-items">
        <van-tab title="出库申请">
            <van-list v-model="stockOut.loading" :finished="stockOut.finished" finished-text="没有更多了" @load="onLoad(stockOut.textType)">
                <normal-order-list v-for="(item, index) in stockOut.dataset" :key="index" :ibase="item.base" :dataset="item.items" :textType="stockOut.textType" class="el-item" />
            </van-list>
        </van-tab>
        <van-tab title="入库申请">
            <van-list v-model="stockEntry.loading" :finished="stockEntry.finished" finished-text="没有更多了" @load="onLoad(stockEntry.textType)">
                <normal-order-list v-for="(item, index) in stockEntry.dataset" :key="index" :ibase="item.base" :dataset="item.items" :textType="stockEntry.textType" class="el-item" />
            </van-list>
        </van-tab>
    </van-tabs>
</template>

<script>
    import { Tab, Tabs, List } from 'vant';

    import NormalOrderList from '../../components/currency/order-item/normal-list-salesman.vue';
    export default {
        name: "record",
        components: {
            [Tab.name]: Tab, [Tabs.name]: Tabs, [List.name]: List,
            NormalOrderList
        },
        data() {
            return {
                tabs: {
                    index: 0
                },
                stockOut: {
                    loading: false,
                    finished: false,
                    textType: 'stockOut',
                    page: 0,
                    list_rows: 10,
                    dataset: []
                },
                stockEntry: {
                    page: 0,
                    list_rows: 10,
                    loading: false,
                    finished: false,
                    textType: 'stockEntry',
                    dataset: []
                }
            }
        },
        mounted() {
            this.tabs.index = this.$route.query.index;
        },
        methods: {
            getOrderList(items) {
                var that = this;
                var status = '';
                switch (items.textType) {
                    case 'stockOut':
                        status = 1;
                        break;
                    case 'stockEntry':
                        status = 1;
                        break;
                }
                var url = '/api/home/order/getlist';
                var param = {
                    page: items.page,
                    list_rows: items.list_rows,
                    utype:6,
                    // status: status,
                    // groupid: 6,
                    token: that.$store.state.options.user.token
                };
                if (items.textType=='stockOut') {
                    param.otype = 1;
                }else {
                    param.status = 1;
                }
                var detail = [];
                this.$util.postRequestInterface(url, param, (res) => {
                    items.page = items.page + 1;
                    if (res.data == '') {
                        items.loading = false;
                        items.finished = true;
                    } else {
                        for (let i of res.data.data) {
                            for (let x of i.detail) {
                                detail.push({
                                    title: x.garbagename,
                                    number: x.weighting_method == 1 ? x.weighting_num : '',
                                    weight: x.weighting_method == 0 ? x.weighting_num : '',
                                    time: that.$moment(i.create_time * 1000).format('YYYY-MM-DD HH:mm:ss'),
                                })
                            }
                            items.dataset.push({
                                base: {
                                    status:i.status,
                                    id:i.id,
                                    number: i.ordernumber,
                                    amount: i.price,
                                    // protect: i.isbaozhi,
                                    price: i.price
                                },
                                items: detail
                            });
                            detail = []
                        }
                        // // 加载状态结束
                        items.loading = false;
                        // // 数据全部加载完成
                        if (items.dataset.length >= res.data.count) {
                            items.finished = true;
                        }
                    }
                })
            },
            onLoad(textType) {
                switch (textType) {
                    case 'stockOut':
                        this.getOrderList(this.stockOut);
                        break;
                    case 'stockEntry':
                        this.getOrderList(this.stockEntry);
                        break;
                }
            }
        },
    }
</script>

<style scoped lang="scss">
    .order-list-items {

        .el-item {
            padding: 0.5rem 1rem 0rem;
        }
    }
</style>
